package uniandes.dermatologia;

import uniandes.dermatologia.models.PhysicalExamination.Symptom;
import uniandes.dermatologia.singleton.DermatologiaUniandesApp;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.CheckBox;
import android.support.v4.app.NavUtils;

public class SymptomsActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_symptoms);
		// Show the Up button in the action bar.
		getActionBar().setDisplayHomeAsUpEnabled(false);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.symptoms, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			// This ID represents the Home or Up button. In the case of this
			// activity, the Up button is shown. Use NavUtils to allow users
			// to navigate up one level in the application structure. For
			// more details, see the Navigation pattern on Android Design:
			//
			// http://developer.android.com/design/patterns/navigation.html#up-vs-back
			//
			NavUtils.navigateUpFromSameTask(this);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	public void onClickNext(View v) {

		final CheckBox cbAlopecia = (CheckBox) findViewById(R.id.cbAlopecia);
		final CheckBox cbBlanching = (CheckBox) findViewById(R.id.cbBlanching);
		final CheckBox cbDesquamation = (CheckBox) findViewById(R.id.cbDesquamation);
		final CheckBox cbPain = (CheckBox) findViewById(R.id.cbPain);
		final CheckBox cbEdema = (CheckBox) findViewById(R.id.cbEdema);
		final CheckBox cbEruption = (CheckBox) findViewById(R.id.cbEruption);
		final CheckBox cbExcoriation = (CheckBox) findViewById(R.id.cbExcoriation);
		final CheckBox cbExfoliation = (CheckBox) findViewById(R.id.cbExfoliation);
		final CheckBox cbHemorrhage = (CheckBox) findViewById(R.id.cbHemorrhage);
		final CheckBox cbPigmentation = (CheckBox) findViewById(R.id.cbPigmentation);
		final CheckBox cbPruritus = (CheckBox) findViewById(R.id.cbPruritus);
		final CheckBox cbOther = (CheckBox) findViewById(R.id.cbOtherSymptoms);

		((DermatologiaUniandesApp) getApplication())
		.getCurrentConsultation().getPhysicalExamination().cleanSymptoms();
		
		if (cbAlopecia.isChecked()) {
			((DermatologiaUniandesApp) getApplication())
					.getCurrentConsultation().getPhysicalExamination()
					.setSymptoms(Symptom.alopecia.toString());
		}
		if (cbBlanching.isChecked()) {
			((DermatologiaUniandesApp) getApplication())
					.getCurrentConsultation().getPhysicalExamination()
					.setSymptoms(Symptom.blanching.toString());

		}
		if (cbDesquamation.isChecked()) {
			((DermatologiaUniandesApp) getApplication())
					.getCurrentConsultation().getPhysicalExamination()
					.setSymptoms(Symptom.desquamation.toString());

		}
		if (cbPain.isChecked()) {
			((DermatologiaUniandesApp) getApplication())
					.getCurrentConsultation().getPhysicalExamination()
					.setSymptoms(Symptom.pain.toString());

		}
		if (cbEdema.isChecked()) {
			((DermatologiaUniandesApp) getApplication())
					.getCurrentConsultation().getPhysicalExamination()
					.setSymptoms(Symptom.edema.toString());

		}
		if (cbEruption.isChecked()) {
			((DermatologiaUniandesApp) getApplication())
					.getCurrentConsultation().getPhysicalExamination()
					.setSymptoms(Symptom.eruption.toString());

		}
		if (cbExcoriation.isChecked()) {
			((DermatologiaUniandesApp) getApplication())
					.getCurrentConsultation().getPhysicalExamination()
					.setSymptoms(Symptom.excoriation.toString());

		}
		if (cbExfoliation.isChecked()) {
			((DermatologiaUniandesApp) getApplication())
					.getCurrentConsultation().getPhysicalExamination()
					.setSymptoms(Symptom.alopecia.toString());

		}
		if (cbHemorrhage.isChecked()) {
			((DermatologiaUniandesApp) getApplication())
					.getCurrentConsultation().getPhysicalExamination()
					.setSymptoms(Symptom.hemorrhage.toString());

		}
		if (cbPigmentation.isChecked()) {
			((DermatologiaUniandesApp) getApplication())
					.getCurrentConsultation().getPhysicalExamination()
					.setSymptoms(Symptom.pigmentation.toString());

		}
		if (cbPruritus.isChecked()) {
			((DermatologiaUniandesApp) getApplication())
					.getCurrentConsultation().getPhysicalExamination()
					.setSymptoms(Symptom.pruritus.toString());

		}

		final CheckBox cbFever = (CheckBox) findViewById(R.id.cbFever);
		final CheckBox cbFacialParalysis = (CheckBox) findViewById(R.id.cbFacialParalysis);
		final CheckBox cbWeightLoss = (CheckBox) findViewById(R.id.cbWeightLoss);

		boolean systemicSymptoms = false;
		
		if (cbFever.isChecked()) {
			((DermatologiaUniandesApp) getApplication())
			.getCurrentConsultation().getPhysicalExamination()
			.setSymptoms(Symptom.fever.toString());
			systemicSymptoms = true;
		}
		if (cbFacialParalysis.isChecked()) {
			((DermatologiaUniandesApp) getApplication())
			.getCurrentConsultation().getPhysicalExamination()
			.setSymptoms(Symptom.facial_paralysis.toString());
			systemicSymptoms = true;
		}
		if (cbWeightLoss.isChecked()) {
			((DermatologiaUniandesApp) getApplication())
			.getCurrentConsultation().getPhysicalExamination()
			.setSymptoms(Symptom.weight_loss.toString());
			systemicSymptoms = true;
		}
		if (cbOther.isChecked()) {
			((DermatologiaUniandesApp) getApplication())
			.getCurrentConsultation().getPhysicalExamination()
			.setSymptoms(Symptom.other.toString());
			systemicSymptoms = true;
		}
		
		if(systemicSymptoms){
			((DermatologiaUniandesApp) getApplication())
			.getCurrentConsultation().getPhysicalExamination()
			.setSymptoms(Symptom.systemic_symptoms.toString());
		}

		Intent intent = new Intent(this, PastActivity.class);
		startActivity(intent);
	}

	public void onClickBack(View v) {
		finish();
	}

}
